//package net.skyedu.utils;
//
//import java.io.File;
//import java.io.InputStream;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.net.URLEncoder;
//import java.util.ArrayList;
//import java.util.List;
//
////import org.apache.commons.httpclient.HttpClient;
////import org.apache.commons.httpclient.methods.PostMethod;
////import org.apache.commons.httpclient.methods.multipart.FilePart;
////import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
////import org.apache.commons.httpclient.methods.multipart.Part;
////import org.apache.commons.httpclient.methods.multipart.StringPart;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.entity.UrlEncodedFormEntity;
//import org.apache.http.client.methods.HttpGet;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.impl.client.DefaultHttpClient;
//import org.apache.http.message.BasicNameValuePair;
//import net.skyedu.utils.StreamTool;
//
////import android.util.Log;
//
//public class MessageService {
//
//	private static final String TAG = "MessageService";
//
//	public static boolean sendData(String name, String password)
//			throws Exception {
//
//		String path = "http://192.168.1.101:8085/web/LoginServlet?name="
//				+ URLEncoder.encode(name) + "&password=" + password;
//
//		URL url = new URL(path);
//		
//		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//		conn.setReadTimeout(5000);
//		conn.setRequestMethod("GET");
//		if (conn.getResponseCode() == 200) {
//			InputStream is = conn.getInputStream();
//			byte[] result = StreamTool.getStreamByBytes(is);
//			String data = new String(result);
//			Log.i(TAG, data);
//			return true;
//		}
//		return false;
//	}
//
//	public static boolean getdata(String name, String password) throws Exception{
//		String path = "http://192.168.1.101:8085/web/LoginServlet?name="
//				+ URLEncoder.encode(name) + "&password=" + password;
//		
//		DefaultHttpClient client=new DefaultHttpClient();
//		
//		HttpGet httpget=new HttpGet(path);
//		HttpResponse  response=client.execute(httpget);
//		if(response.getStatusLine().getStatusCode()==200){
//			InputStream is = response.getEntity().getContent();
//			byte[] result = StreamTool.getStreamByBytes(is);
//			String data = new String(result);
//			Log.i(TAG, data);
//			return true;
//		}
//		
//		
//		return false;
//	}
//	
//	public static boolean postData(String name, String password)
//			throws Exception {
//		String path = "http://192.168.1.101:8085/web/LoginServlet";
//		URL url = new URL(path);
//		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//		conn.setReadTimeout(5000);
//		conn.setRequestMethod("POST");
//		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//		String content="name="+name+"&password="+password;
//		byte[] data=content.getBytes();
//		conn.setRequestProperty("Content-Length", data.length+"");
//		conn.setDoOutput(true);
//		conn.getOutputStream().write(data);
//		
//		if (conn.getResponseCode() == 200) {
//			InputStream is = conn.getInputStream();
//			byte[] result = StreamTool.getStreamByBytes(is);
//			String resultdata = new String(result);
//			//Log.i(TAG, resultdata);
//			return true;
//		}
//		return false;
//	}
//	public static boolean postClientData(String name, String password)
//			throws Exception {
//		String path = "http://192.168.1.101:8085/web/LoginServlet";	
//		DefaultHttpClient client =new DefaultHttpClient();
//		HttpPost post=new HttpPost(path);
//		List<BasicNameValuePair> parameters=new ArrayList<BasicNameValuePair>();
//		parameters.add(new BasicNameValuePair("name", name));
//		parameters.add(new BasicNameValuePair("password", password));
//		post.setEntity(new UrlEncodedFormEntity(parameters));
//		
//		HttpResponse  response=client.execute(post);
//		if(response.getStatusLine().getStatusCode()==200){
//			InputStream is = response.getEntity().getContent();
//			byte[] result = StreamTool.getStreamByBytes(is);
//			String data = new String(result);
//			Log.i(TAG, data);
//			return true;
//		}
//		
//		return false;
//	}
//
//	public static boolean postFile(String name, String password, String path) {
//		PostMethod filePost = new PostMethod(
//				"http://192.168.1.101:8080/web/UploadServlet");
//		try {
//			Part[] parts = { new StringPart("name", name),
//					new StringPart("password", password),
//					new FilePart("pic", new File(path)) };
//
//			filePost.setRequestEntity(new MultipartRequestEntity(parts,
//					filePost.getParams()));
//			HttpClient cilent = new HttpClient();
//			cilent.getHttpConnectionManager().getParams()
//					.setConnectionTimeout(5000);
//
//			cilent.executeMethod(filePost);
//			return true;
//		} catch (Exception e) {
//			e.printStackTrace();
//			return false;
//		} finally {
//			filePost.releaseConnection();
//		}
//	}
//}
